#ifndef SWEGL_TEXTURE_UNIT_H
#define SWEGL_TEXTURE_UNIT_H

#include "swegl/common.h"

namespace swegl
{

class Texture;

class TextureUnit
{
public:
	TextureUnit();

	void setTexture(Texture *texture);
	uint32 sample(float u, float v) const;

private:
	const Texture *m_texture;
};

inline TextureUnit::TextureUnit() : m_texture(0)
{
}

inline void TextureUnit::setTexture(Texture *texture)
{
	m_texture = texture;
}

inline uint32 TextureUnit::sample(float fu, float fv) const
{
	const Surface *mipmap = m_texture->surface(0);
	sint u = static_cast<sint>((fu * mipmap->width())) % mipmap->width();
	sint v = static_cast<sint>((fv * mipmap->height())) % mipmap->height();
	return mipmap->data<uint32>()[u + v * mipmap->height()];
}

}

#endif 
